import {
  openPicker,
  Config,
  openCamera,
  // CameraConfig,
} from '@baronha/react-native-multiple-image-picker';

import { ToastMessage } from './toastMessage';

const singleConfig: Config = {
  primaryColor: '#FB9300',
  backgroundDark: '#2f2f2f',
  numberOfColumn: 4,
  mediaType: 'image',
  selectBoxStyle: 'number',
  selectMode: 'single',
  theme: 'dark',
  isHiddenOriginalButton: false,
};

// const cameraConfig: CameraConfig = {
//   mediaType: 'image',
// };

/**
 * 从图库中选择（单张）
 * @param config
 * @returns
 */
export const onPickerSingle = async (config?: Config) => {
  try {
    return await openPicker({ ...singleConfig, ...config }).then((res) => res[0]);
  } catch (e) {
    ToastMessage.error((e as Error).message);
  }
};

/**
 * 从图库中选择（多张）
 * @param config
 * @returns
 */
export const onPickerMultiple = async (config?: Config) => {
  try {
    return await openPicker({
      ...singleConfig,
      selectMode: 'multiple',
      ...config,
    });
  } catch (e) {
    ToastMessage.error((e as Error).message);
  }
};

/**
 * 从相机中选择
 *
 */
export const onCamera = async (config?: Config) => {
  try {
    return await openCamera({ ...singleConfig, ...config });
  } catch (e) {
    ToastMessage.error((e as Error).message);
  }
};
